package com.dzx.design.behavioral.memento;

/**
 * @author dzx
 * @ClassName:
 * @Description: 备忘录模式
 * @date 2019年08月14日 16:40:02
 */
public class Test {
    public static void main(String[] args){
        ArticleMementoManager articleMementoManager = new ArticleMementoManager();

        Article article = new Article("如影随形的设计模式A", "手机内容A", "手机图片A");
        System.out.println("手记完整信息:"+article);
        //存档一次
        ArticleMemento articleMemento = article.saveToMemento();
        articleMementoManager.addMemento(articleMemento);
        System.out.println(articleMemento+"【暂存成功】");

        //修改手机start
        System.out.println("修改手记start");
        article.setTitle("如影随形的设计模式B");
        article.setContent("手机内容B");
        article.setImgs("手机图片B");
        System.out.println("修改手记end");
        System.out.println("手记完整信息:"+article);

        articleMemento = article.saveToMemento();
        articleMementoManager.addMemento(articleMemento);
        System.out.println(articleMemento+"【暂存成功】");

        article.setTitle("如影随形的设计模式C");
        article.setContent("手机内容C");
        article.setImgs("手机图片C");

        System.out.println("暂存回退start");

        System.out.println("回退出栈1次");
        articleMemento = articleMementoManager.getMemento();
        article.undoFromMemento(articleMemento);

        System.out.println("回退出栈2次");
        articleMemento = articleMementoManager.getMemento();
        article.undoFromMemento(articleMemento);

        System.out.println("暂存回退end");
        System.out.println("手记完整信息:"+article);

    }
}
